|
|
|
|
|
|
|
by the actual speed of your code. Other factors, such as video speed, network delays, or disk activities, are usually the limiting factor for your application. However, you may find areas in your application where the speed of your code is the limiting factor, especially for frequently called routines. When that's the case, you can use the following techniques to increase your application's speed: |
|
|
|
|
|
|
|
|
Avoid using Variant variables |
|
|
|
|
|
|
|
|
Use Long integer variables and integer math |
|
|
|
|
|
|
|
|
Cache frequently used properties in variables |
|
|
|
|
|
|
|
|
Replace procedure calls with inline procedures |
|
|
|
|
|
|
|
|
Use constants whenever possible |
|
|
|
|
|
|
|
|
Pass arguments ByVal instead of ByRef |
|
|
|
|
|
|
|
|
Even if you're not optimizing your code for speed, it helps to be aware of these issues and their underlying concepts. As you get into the habit of choosing more efficient methods while you create your code, the gains can add up to a noticeable improvement of your application speed. |
|
|
|
|
|
|
|
|
Replacing Code with New Functions |
|
|
|
|
|
|
|
|
Visual Basic 6 includes several new language functions that can be used to replace older less efficient ways of data processing. By replacing these older multiple function statements with the newer functions, the application will perform better. The following section of code was used to search each element of an array for a specific string value and place those elements into a second array: |
|
|
|
|
|
|
|
|
J = 0
For I = 0 To 99
If Instr(arrInput(I), Demo) > 0 then
J = J + 1
ReDim arrFound(J)
arrFound(I) = arrInput(I)
End If
Next I |
|
|
|
|
|
|
|
|
As you can see, while this code works, it does require some processing time from the computer to perform the loop and the If statement test. Using the new Filter function, this process would be reduced to the following one statement: |
|
|
|
|
|
|
|
|
arrFound = Filter(arrInput, Demo, True, vbTextCompare) |
|
|
|
|
|
|
|
|
By using this statement, you are making use of an internal function to perform the task instead of standard basic code. Table 19.1 lists the new functions and a description. You should take a few minutes to investigate these new commands to see when you can, or should, use them. |
|
|
|
|
|